#include <bits/stdc++.h>

#define int long long

using namespace std;

const int kMaxN = 4e5 + 10;

int T;

int opt_list[kMaxN];

namespace Task1 {

   set<int> s;

   void main() {
      for (int t = 1; t <= T; ++t) {
         int x = opt_list[t];
         if (s.find(x) != s.end()) s.erase(x);
         else s.insert(x);
         if (!s.size()) {
            cout << 0 << '\n';
            continue;
         }
         vector<int> a;
         vector<pair<int, int> > b;
         for (auto it : s) a.emplace_back(it);
         int pre = 0, suf = 0;
         for (int i = 0; i < a.size(); ++i) {
            pre += a[i], suf += a[a.size() - i - 1];
            b.emplace_back(pre, suf);
         }
         int lst = b[0].first;
         int ans = 0;
         for (int i = 0; i < b.size(); ++i) {
            //cout << b[i].first << ' ' << b[i].second << '\n';
            if (i == b.size() - 1) {
               ans += b[i].second - lst;
            }
            else {
               if (b[i].second < b[i + 1].first) {
                  ans += b[i].second - lst;
                  lst = b[i + 1].first;
               }
            }
         }
         cout << ans << '\n';
      }
   }
}

namespace Task2 {
   const int kMaxN = 3e4 + 10;

   bool vis[kMaxN];

   vector<int> a;

   void main() {
      for (int t = 1; t <= T; ++t) {
         int x = opt_list[t];
         vis[x] ^= 1;
         a.clear();
         for (int i = 1; i <= (int)3e4; ++i) {
            if (vis[i]) a.emplace_back(i);
         }
         int pre = 0, suf = 0;
         int lst = 0;
         int ans = 0;
         for (int i = 0; i + 1 < a.size(); ++i) {
            pre += a[i], suf += a[a.size() - i - 1];
            if (i == 0) lst = pre;
            if (i == a.size() - 2) {
               ans += suf - lst;
            }
            else if (suf < pre + a[i + 1]) {
               ans += suf - lst;
               lst = pre + a[i + 1];
            }
         }
         cout << ans << '\n';
      }
   }
}

namespace Task3 {
   set<int> s;
   int sum;

   void main() {
      for (int t = 1; t <= T; ++t) {
         int x = opt_list[t];
         if (s.find(x) != s.end()) {
            s.erase(x);
            sum -= x;
         }
         else {
            s.insert(x);
            sum += x;
         }
         if (!s.size()) {
            cout << 0 << '\n';
            continue;
         }
         if (s.size() <= 100) {
            vector<int> a;
            vector<pair<int, int> > b;
            for (auto it : s) a.emplace_back(it);
            int pre = 0, suf = 0;
            for (int i = 0; i < a.size(); ++i) {
               pre += a[i], suf += a[a.size() - i - 1];
               b.emplace_back(pre, suf);
            }
            int lst = b[0].first;
            int ans = 0;
            for (int i = 0; i < b.size(); ++i) {
               //cout << b[i].first << ' ' << b[i].second << '\n';
               if (i == b.size() - 1) {
                  ans += b[i].second - lst;
               }
               else {
                  if (b[i].second < b[i + 1].first) {
                     ans += b[i].second - lst;
                     lst = b[i + 1].first;
                  }
               }
            }
            cout << ans << '\n';
         }
         else {
            cout << sum - (*s.begin()) - (*s.begin()) << '\n';
         }
      }
   }
}

signed main() {
   freopen("kte.in", "r", stdin);
   freopen("kte.out", "w", stdout);

   ios::sync_with_stdio(false);
   cin.tie(0), cout.tie(0);

   cin >> T;
   int mx = 0;
   for (int i = 1; i <= T; ++i) cin >> opt_list[i], mx = max(mx, opt_list[i]);
   if (T <= 1000) Task1::main();
   else if (T <= (int)3e4 && mx <= (int)3e4) Task2::main();
   else
      Task3::main();

   return 0;
}
